<template></template>

<script>
import { selectDiserRuleDetail } from "@/api/datascan/scanresults/table";
import { _deepClone } from "@/utils";

export default {
  name: "index",
  data() {
    return {
      ids: [],
      chooseColumnName: [],
      form: {
        chooseIds: [],
      },
      tempList: [],
      nums: 2,
    };
  },
  methods: {
    moreTool(operate) {
      let nums = operate === "two" ? 2 : 5;
      if (this.nums !== nums) {
        this.initDataByNums(nums);
      }
      this.nums = nums;
    },
    /**
     * 数据初始化
     */
    initDataByNums(nums) {
      this.handleSetDataByColumn(nums);
    },
    /**
     * 参数传值数据进行处理
     */
    handleSetDataByColumn(nums) {
      this.loading = true;

      let sample = [],
        other = [];

      if (this.info.interfaceSensitiveRuleList.length) {
        sample = this.info.interfaceSensitiveRuleList.reduce((r, c) => {
          if (c.sensitiveSourceData) r.push(c.sensitiveSourceData);
          return r;
        }, []);
      }

      if (sample && sample.length < nums) {
        for (let i = 0; i < nums - sample.length; i++) {
          other.push("");
        }
      } else if (sample && sample.length > nums) {
        sample.splice(nums, sample.length - nums);
      }
      this.list = [
        {
          url: this.info.url,
          systemName: this.info.businessName,
          sample: [...sample, ...other],
          typeIds: this.getTypeIds(),
        },
      ];
      this.tempList = _deepClone(this.list);
      this.loading = false;
    },

    getTypeIds() {
      return [];
    },
    // /**
    //  * 参数传值数据进行处理
    //  */
    // handleSetDataByColumn(nums) {
    //   console.log(this.info);
    //   this.loading = true;
    //   let sample = ["", ""];

    //   this.list = [
    //     {
    //       url: this.info.url,
    //       systemName: this.info.businessName,
    //       sample,
    //       typeIds: [],
    //     },
    //   ];

    //   // let sample = this.info?.remark.split(",") || ["", ""];
    //   // if (sample && sample.length < nums) {
    //   //   for (let i = 0; i < nums - sample.length; i++) {
    //   //     sample.push("");
    //   //   }
    //   // } else if (sample && sample.length > nums) {
    //   //   sample.splice(nums, sample.length - nums);
    //   // }
    //   // this.list = [
    //   //   {
    //   //     columnName: this.info.columnName,
    //   //     columnRemark: this.info.columnRemark,
    //   //     remark: sample,
    //   //     typeIds: this.info[this.key]?.split(",") || [],
    //   //   },
    //   // ];
    //   this.loading = false;
    // },

    handleData(type) {
      return this.list[0].typeIds.map((item) => ({ [type]: item }));
    },

    /**
     * 打开批量设置弹窗
     */
    handleSet() {
      this.open = true;
    },
    /**
     * 关闭批量设置弹窗
     */
    cancel() {
      this.form.chooseIds = [];
      this.open = false;
    },

    submitForm() {
      this.buttonLoading = true;
      this.list.forEach((item) => {
        if (this.ids.includes(item.scanResultId)) {
          item.typeIds = this.form.chooseIds;
          item.ruleIds = this.form.chooseIds;
        }
      });
      this.buttonLoading = false;
      this.ids = [];
      this.chooseColumnName = [];
      this.cancel();
    },

    changeType(v) {
      // console.log(this.list);
    },

    handleClose(index) {
      this.chooseColumnName.splice(index, 1);
      this.ids.splice(index, 1);
    },
  },
};
</script>

<style scoped></style>
